/*
 * table_CppTokenList.c
 *
 *  Created on: 2012/03/30
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
/*KIND_PPTOKENLIST		*/
typedef struct _PPTOKENLIST {
	U2 usPPTokenKind;	/* 2 */
	AST astLoc;	/* 3 */
	AST astMcr;
	AST astName;/* 4 */
}PPTOKENLIST, *PPPTOKENLIST;
/*KIND_PPTOKENLIST		*/
#define TableSize  (sizeof(PPTOKENLIST))
#define TableType  PPPTOKENLIST
#define stTable stPPTokenListManager.memoryBlocks
#define maxTable stPPTokenListManager.maxRecordNum
#define  maxNumPerBlk  (stPPTokenListManager.astMaxNum_Block)


/* private field */

static TABLEMANAGER stPPTokenListManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stPPTokenListManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stPPTokenListManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stPPTokenListManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stPPTokenListManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stPPTokenListManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}
//	USHORT_PPTOKENKIND
static U2 getPPTokenKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usPPTokenKind;
}
static U2 setPPTokenKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usPPTokenKind = value;
}
//	IDX_LOCATION
static AST getLocation( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLoc;
}
static AST setLocation( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLoc = value;
}
//	IDX_LOCATION
static AST getMacroExtend( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMcr;
}
static AST setMacroExtend( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astMcr = value;
}
//STR_TOKENNAME
static CHAR* getTokenName( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return "";
	}
	return stCoreLabelStrAccess.getStr( pTbl->astName );
}
static AST setTokenName( AST index, PSZ str )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astName = stCoreLabelStrAccess.addStr(str);
}
const PPTOKENLIST_ACCESS stCorePPTokenListAccess =
{
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,
		{
				getLocation,
				setLocation
		},
		{
				getMacroExtend,
				setMacroExtend
		},
		{
				getTokenName,
				setTokenName
		},
		{
				getPPTokenKind,
				setPPTokenKind
		}
};
/* end of file */
